package com.zidian.leader.api;

import com.zidian.leader.entity.HttpResult;

import rx.functions.Func1;

/**
 * Created by GongCheng on 2016/11/3.
 */

public class HttpResultFunc<T> implements Func1<HttpResult<T>,T> {
    /**
     * 用来统一处理Http的resultCode,并将HttpResult的Data部分剥离出来返回给subscriber
     *
     * @param </T> Subscriber真正需要的数据类型，也就是Data部分的数据类型
     */
    @Override
    public T call(HttpResult<T> re) {
        if (re.getCode() != 200) {
            throw new ApiException(re.getMessage());
        }
        return re.getData();
    }
}
